<?php
class fwTools
{
	public static function mkdirTree($path, $dirs)
	{
		$dirs = explode('/', $dirs);
		foreach ($dirs as $dir)
		{
			$path.='/'.$dir;
			if(!is_dir($path))	
			{
				if(!@mkdir($path))
				{
					return false;
				}
			}
		}
		return true;
	}
	
	public static function compareVersions($v1, $v2)
	{
		$v1 = explode('.', $v1);
		$v2 = explode('.', $v2);
		foreach ($v1 as $i => $v)
		{
			if(intval($v1[$i])<intval($v2[$i]))
				return -1;
			if(intval($v1[$i])>intval($v2[$i]))
				return 1;
		}
		return 0;
	}
	
	public static function saveConfig($name)
	{
		global $project_path, $conf;
		file_put_contents($project_path.'/conf/'.$name.'.conf.php5', '<?php
$conf[\''.$name.'\']='.var_export($conf[$name], true).';
?>');
	}
	
	public static function var_export_string($object)
	{
		if(is_array($object))
		{
			$tmp = array();
			foreach($object as $key => $value)
			{
				$tmp[] = '  \''.$key .'\' => '.fwTools::var_export_string($value);
			}
			return 'array(
'.implode(',
', $tmp).'
)';
			
		}
		elseif(is_numeric($object))
		{
			return addslashes($object);
		}
		else
		{
			return '\''.addslashes($object).'\'';
		}
	}
}
?>